package com.origon360.Services;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.origon.entities.Role;
import com.origon.entities.User;

@Stateless
public  class UserService {
	
	@PersistenceContext
	EntityManager em;
	
	public User findUserByUserName(String userName){
		 return em.createQuery("FROM User u WHERE u.username =:userName", User.class)
				 .setParameter("userName", userName).getSingleResult();
	}
	
	public Role findRoleByName(String roleName){
		return em.createQuery("FROM Role r WHERE r.roleName =:roleName", Role.class)
				.setParameter("roleName", roleName).getSingleResult();
	}

	public Role getUserRole(){
		return findRoleByName("user");
	}
}
